package com.bw.kf.mvvm


import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class HttpUser {
    companion object{
        val client=OkHttpClient.Builder()
            .connectTimeout(10,TimeUnit.SECONDS)
            .writeTimeout(10,TimeUnit.SECONDS)
            .readTimeout(10,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                val token=SPUtils.getInstance().getString("token")
                val request=it.request().newBuilder().addHeader("Authori-zation",token).build()
                it.proceed(request)
            }
            .build()
        fun getRetrofit():Retrofit{
            val retrofit=Retrofit.Builder()
                .client(client)
                .baseUrl("http://10.161.9.80:7456")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
            return retrofit
        }
    }
}